package com.furns.dao.impl;

import com.furns.dao.BasicDAO;
import com.furns.dao.MemberDAO;
import com.furns.entity.Member;

/**
 * @author $邓琰琰
 * @version 1.0
 */
public class MemberDAOImpl extends BasicDAO<Member> implements MemberDAO {
    /**
     * 通过用户名返回对应的Member
     * @param username
     * @return 对应的Member，如果没有该Member，返回null
     */
    @Override
    public Member queryMemberByUsername(String username) {
        String sql = "SELECT `id`,`username`,`password`,`email` FROM `member`\n" +
                " WHERE `username`=?";

        return querySingle(sql, Member.class, username);
    }

    /**
     * 保存一个会员
     * @param member 传入Member对象
     * @return 返回-1 就是失败，返回其它的数字就是受影响的行数
     */
    @Override
    public int saveMember(Member member) {
        String sql = " INSERT INTO `member`(`username`,`password`,`email`) \n" +
                " VALUES(?,MD5(?), ?)";
        return update(sql, member.getUsername(), member.getPassword(), member.getEmail());
    }
}
